import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * roleDataAuthorityManagement - 租户级权限维护tab页 - 采购品类 model
 * @date: 2018-7-31

 */
import { getResponse } from 'utils/utils';
import { changeAuthority as _changeAuthority, copyAuthority as _copyAuthority, queryUserInfo, fetchTabList as _fetchTabList } from "../../services/roleDataAuthorityService";
export default {
  namespace: 'roleDataAuthorityManagement',
  state: {
    authorList: [],
    data: {
      list: []
    }
  },
  effects: {
    fetchUserInfo: /*#__PURE__*/_regeneratorRuntime.mark(function fetchUserInfo(_ref, _ref2) {
      var payload, call, put, response, data;
      return _regeneratorRuntime.wrap(function fetchUserInfo$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(queryUserInfo, payload);

            case 4:
              response = _context.sent;
              data = getResponse(response);

              if (!data) {
                _context.next = 9;
                break;
              }

              _context.next = 9;
              return put({
                type: 'queryUserInfo',
                payload: data
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, fetchUserInfo);
    }),
    copyAuthority: /*#__PURE__*/_regeneratorRuntime.mark(function copyAuthority(_ref3, _ref4) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function copyAuthority$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_copyAuthority, payload);

            case 4:
              response = _context2.sent;
              return _context2.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, copyAuthority);
    }),
    changeAuthority: /*#__PURE__*/_regeneratorRuntime.mark(function changeAuthority(_ref5, _ref6) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function changeAuthority$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.next = 4;
              return call(_changeAuthority, payload);

            case 4:
              response = _context3.sent;
              return _context3.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, changeAuthority);
    }),
    fetchTabList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchTabList(_ref7, _ref8) {
      var payload, call, put, response, data;
      return _regeneratorRuntime.wrap(function fetchTabList$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call, put = _ref8.put;
              _context4.next = 4;
              return call(_fetchTabList, payload);

            case 4:
              response = _context4.sent;
              data = getResponse(response);

              if (!data) {
                _context4.next = 9;
                break;
              }

              _context4.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  authorList: data
                }
              });

            case 9:
              return _context4.abrupt("return", data);

            case 10:
            case "end":
              return _context4.stop();
          }
        }
      }, fetchTabList);
    })
  },
  reducers: {
    queryUserInfo: function queryUserInfo(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        data: action.payload
      });
    },
    updateState: function updateState(state, _ref9) {
      var payload = _ref9.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};